﻿Public Class FormPTGBBMWDJC
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Dim txt As TextBox
    Dim objMstTechnology As New clsMstTechnology
    Dim objFlbMst As New clsFlbMst
    Dim objPTGBBMWDJC As New clsPTGBBMWDJC
    Dim update_status As String = "INSERT_TYPE"
    Dim en As entityPTGBBMWDJC
    Dim _sys_id As String

    Public Property Sys_id As String
        Get
            Return _sys_id
        End Get
        Set(value As String)
            _sys_id = value
        End Set
    End Property
    Private Sub FormPTGBBMWDJC_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = GetIniFile("JS", "JS5", "", g_jsInitFileName)
        txtDate.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True
        txtDate.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True
        initForm()
        If _sys_id <> "" Then
            update_status = "UPDATE_TYPE"
            setContentBySysid()
        Else
            update_status = "INSERT_TYPE"
        End If
    End Sub

    Private Sub initForm()
        Dim dtMstTechnology As DataTable = objMstTechnology.getListByName(Me.Text)
        If dtMstTechnology.Rows.Count > 0 Then
            txtId.Text = dtMstTechnology.Rows(0)("sys_id").ToString()
            txtRequirement.Text = dtMstTechnology.Rows(0)("requirement").ToString()
            txtControlPoint.Text = dtMstTechnology.Rows(0)("control_point").ToString()
        End If
        Dim dtFlbMst As DataTable = objFlbMst.selectAll(String.Empty)
        cmb_flb_type.ValueMember = "mst_value"
        cmb_flb_type.DisplayMember = "mst_value_name"
        cmb_flb_type.DataSource = dtFlbMst
        If dtFlbMst.Rows.Count > 0 Then
            cmb_flb_type.SelectedIndex = 0
        End If
        Dim TDate As String = Now.ToString()
        txtDate.Text = TDate
        txt_surface_temp.Value = 0
    End Sub

    Private Sub setContentBySysid()
        Dim dt As DataTable = objPTGBBMWDJC.selectBySysid(_sys_id)
        If dt.Rows.Count > 0 Then
            Dim row As DataRow = dt.Rows(0)
            txtRequirement.Text = row("requirement")
            txtId.Text = row("technology_id")
            txtControlPoint.Text = row("control_point")
            txtDate.Text = row("oper_date")
            cmb_flb_type.Text = row("flb_type")
            txt_surface_temp.Text = row("surface_temp")
            If row("surface_abnormal") = 1 Then
                surface_abnormal_OK.Checked = True
            End If
            If row("surface_abnormal") = 0 Then
                surface_abnormal_NG.Checked = True
            End If
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_surface_temp.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub setEntity()
        en = New entityPTGBBMWDJC
        With en
            .sys_id = _sys_id
            .factory_id = "TS"
            .technology_id = txtId.Text
            .oper_date = txtDate.Text
            .flb_type = cmb_flb_type.Text
            .surface_temp = txt_surface_temp.Text
            .surface_abnormal = IIf(surface_abnormal_OK.Checked = True, "1", "0")
            .oper = usr
        End With
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(txtDate.Text.Trim()) Then
            MsgBox("请选择操作日期", vbYes, "提示")
            Exit Sub
        End If
        setEntity()
        If update_status = "INSERT_TYPE" Then
            If objPTGBBMWDJC.insert(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                initForm()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
        If update_status = "UPDATE_TYPE" Then
            If objPTGBBMWDJC.update(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                CType(Owner, FormPTGBBMWDJCRecord).setDgvData()
                Close()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
    End Sub

End Class

Public Class entityPTGBBMWDJC
    Public sys_id As String
    Public factory_id As String '工厂ID
    Public technology_id As String '工艺ID
    Public oper_date As String '操作日期
    Public flb_type As String '规格型号
    Public surface_temp As String '表面检测温度
    Public surface_abnormal As String '板面有无异常
    Public oper As String '操作人
End Class